#include <QtGui/QApplication>
#include "mainwindow.h"
#include "formsrv.h"
#include <QDateTime>
#include <QTextCodec>
#include <QDesktopWidget>
#include <QtSingleApplication>
#include <QCoreApplication>
#include <QSettings>
#include <QFile>
#include "mydatebase.h"
#include "logmsg.h"
#include "mydatebase.h"
#include "loginform.h"
#include "dealexcelfile.h"
#include <QFile>
#include <QDir>
int main(int argc, char *argv[])
{
    QtSingleApplication app(argc,argv);
    if(app.isRunning())
    {
        app.sendMessage("raies");
        return EXIT_SUCCESS;
    }
    //注册自定义类型,用于信号槽
    qRegisterMetaType<myQueue>("myQueue");
    qRegisterMetaType<myVehInfo>("myVehInfo");
    //QApplication a(argc, argv);
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QCoreApplication::addLibraryPath("./plugins");
    //加载样式表
    QFile qss("./qssfile/style.qss");
    qss.open(QFile::ReadOnly);
    app.setStyleSheet(qss.readAll());
    qss.close();
    getDB()->InitDB();
    getDealExecl()->Init();
    app.setActivationWindow(getForm());
    getForm()->move((QApplication::desktop()->width() -getForm()->width())/2,(QApplication::desktop()->height() - getForm()->height())/2);
    if(!QFile::exists("./Server.ini"))
    {
        //qDebug()<<"file did not exist";
    }
    QString path = QDir::currentPath()+"/log";
    QSettings setting("./Server.ini",QSettings::IniFormat);
    quint16 model = setting.value("ListenPort/UseModel",0).toUInt();
    if(model == 1)
    {
        //getForm()->show();
        getForm()->slot_LoadRoadInfo();
        getForm()->showMaximized();
        getLogMsg()->SetLogPath(path);
        getLogMsg()->InitLog("AdminMonitor");
        getLogMsg()->iLogMsg("监控事件:监控程序打开");
        return app.exec();
    }
    else
    {
        LoginForm loginForm;
        loginForm.move((QApplication::desktop()->width() -loginForm.width())/2,(QApplication::desktop()->height() - loginForm.height())/2);
        loginForm.show();
        //getForm()->showMaximized();
        loginForm.setWindowTitle(QObject::tr("车型识别监控系统"));
        loginForm.StartLogin();
        getLogMsg()->SetLogPath(path);
        getLogMsg()->InitLog("Monitor");
        getLogMsg()->iLogMsg("监控事件:监控程序打开");
        return app.exec();
    }
}
